<template>
    <h2>修改门店信息</h2>
    <table>
        <tr>
            <td>门店名称</td>
            <td>
                <input type="text" v-model="lists.sname">
            </td>
        </tr>
        <tr>
            <td>门店图片</td>
            <td>
                <input type="file" @change="imahomskw" v-if="lists.spicture" :src="src">
                
            </td>
        </tr>
        <tr>
            <td>门店地址</td>
            <td>
                <input type="text" v-model="lists.saddress">
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="修改" @click="updowksmws">
            </td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import {onMounted, reactive, toRefs} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    lists:[],
    src:''
  })
  let {lists,src} =toRefs(data)

  onMounted(()=>{
    getfill()
  })

  const imahomskw=(e:any)=>{
    var form=new FormData()
    var obj=e.target.files[0]
    form.append('file',obj)
    axios({
        url:'/api/Upfile/Upload',
        method:'post',
        data:form
    })
    .then(res=>{
        if(res.data.code==11){
            alert(res.data.ms)
            return;
        }else if(res.data.code==12){
            alert(res.data.ms)
            return;
        }else{
            src.value='https://localhost:7246'+res.data.filename;
            lists.value.spicture=res.data.filename;
        }
    })
  }

  const getfill=()=>{
    let obj={
        sid:route.query.sid
    }
    axios({
        url:'/api/Store/Selecid',
        method:'get',
        params:obj
    })
    .then(res=>{
        lists.value=res.data.data;
    })
  }

  const updowksmws:any=(sid:any)=>{
    let obj={
        "sid": route.query.sid,
  "sname": lists.value.sname,
  "spicture":lists.value.spicture,
  "saddress": lists.value.saddress
    }
    console.log(obj)
    axios({
        url:'/api/Store/Updstore',
        method:'post',
        data:obj
    })
    .then(res=>{
        console.log(res)
        if(res.data.data==1){
            alert("修改门店信息成功")
            router.push('showstore')
        }else{
            alert("修改门店信息失败")
        }
    })
    .catch(err=>{
        console.log(err)
    })
  }
  </script>
  
  <style scoped>
  
  </style>